﻿using Newtonsoft.Json;
using System;
using T.FAS.Runtime.Base.Entity;

namespace T.FAS.Runtime.Metadata.Entity.DataModel
{
    /// <summary>
    /// 列权限视图
    /// </summary>
    [Serializable]
    public class ColumnPermissionView
    {
        public string ID { get; set; }
        public string ColumnName { get; set; }
        public string DisplayName { get; set; }
        public bool IsEnableColumnPermission { get; set; }
        public string MaskingRulesContent { get; set; }
        public string DoId { get; set; }
        public string DoCode { get; set; }
        public string DoName { get; set; }
        public string LogicTableName { get; set; }

        [JsonIgnore]
        private MaskingRule _maskingRule;

        /// <summary>
        /// 掩码设置实例
        /// </summary>
        [JsonIgnore]
        public MaskingRule MaskingRule
        {
            get
            {
                if (_maskingRule == null)
                {
                    if (!string.IsNullOrEmpty(MaskingRulesContent))
                    {
                        try
                        {
                            _maskingRule = JsonConvert.DeserializeObject<MaskingRule>(MaskingRulesContent);
                        }
                        catch
                        {
                            _maskingRule = new MaskingRule();
                        }
                    }
                    else
                    {
                        _maskingRule = new MaskingRule();
                    }
                }
                return _maskingRule;
            }
        }
    }
}
